package com.huixiaodian.baselibrary.manage;

import android.annotation.SuppressLint;
import android.content.Context;

import com.huixiaodian.baselibrary.common.Config;
import com.huixiaodian.baselibrary.utils.SharedPreferencesUtil;

public class CookieManager {

    private String cookie;
    private final Context context;

    @SuppressLint("StaticFieldLeak")
    private static CookieManager manager;

    private CookieManager(Context context){
        this.context = context;
    }

    public static CookieManager getInstance(Context context){
        if(manager == null){
            synchronized (CookieManager.class){
                if (manager == null)
                    manager = new CookieManager(context);
            }
        }
        return manager;
    }

    public String getCookie(){
        if(cookie == null){
            SharedPreferencesUtil sharedPreferencesUtil = SharedPreferencesUtil.getInstance(context);
            cookie = sharedPreferencesUtil.getString(Config.JSESSIONID_KEY);
        }
        return cookie;
    }
}
